/**
 * 基础菜单 房间管理
 */
<template>
  <div>    
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>房间管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="搜索：">
        <el-input size="small" v-model="formInline.hotel_id" placeholder="酒店编号"></el-input>
      </el-form-item>
      <el-form-item label="">
        <el-input size="small" v-model="formInline.type" placeholder="套餐"></el-input>
      </el-form-item>

      <!-- <el-form-item label="">
        <el-input size="small" v-model="formInline.price" placeholder="房间价格"></el-input>
      </el-form-item> -->
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
        <!-- <el-button size="small" type="primary" icon="el-icon-plus" @click="handleEdit()">添加</el-button> -->
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" type="selection" width="60">
      </el-table-column>
       <el-table-column sortable prop="hotel_id" label="酒店编号" width="200" align="center">
      </el-table-column>
      <el-table-column sortable prop="hotelname" label="酒店名称" width="200" align="center">
        <!-- <template slot-scope="scope">
          {{scope.row.hotelname}}
        </template> -->
      </el-table-column>
      <el-table-column sortable prop="type" label="房型" width="200" align="center">
      </el-table-column>
      <el-table-column sortable prop="rprice" label="房间价格" width="200" align="center">
        <template slot-scope="scope">￥{{scope.row.rprice}}</template>   
      </el-table-column>
       <el-table-column sortable prop="empty" label="空余房间" width="200" align="center">
      </el-table-column>
      <!-- <el-table-column sortable prop="editTime" label="修改时间" width="200">
        <template slot-scope="scope">
          <div>{{scope.row.editTime|timestampToTime}}</div>
        </template>
      </el-table-column> -->
      <!-- <el-table-column sortable prop="editUser" label="修改人" width="300">
      </el-table-column> -->
      <el-table-column align="center" label="操作" min-width="200" >
        <template slot-scope="scope">
          <el-button size="mini" @click.native="handleEdit(scope.$index, scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
    <!-- 编辑界面 -->
     <el-dialog :title="title" :visible.sync="editFormVisible" width="30%" @click='closeDialog("editForm")'>
      <el-form label-width="120px" :model="editForm" :rules="rules" ref="editForm">
        <el-form-item label="序号" prop="rid">
          <el-input size="small" v-model="editForm.rid" auto-complete="off" placeholder="请输入酒店号"></el-input>
        </el-form-item>
         <el-form-item label="酒店编号" prop="hotel_id">
          <el-input size="small" v-model="editForm.hotel_id" auto-complete="off" placeholder="请输入酒店号"></el-input>
        </el-form-item>
        <el-form-item label="酒店名称" prop="hotelname">
          <el-input size="small" v-model="editForm.hotelname" auto-complete="off" placeholder="请输入酒店名称"></el-input>
        </el-form-item>
        <el-form-item label="房型" prop="type">
          <el-input size="small" v-model="editForm.type" auto-complete="off" placeholder="请输入房型"></el-input>
        </el-form-item>
           <el-form-item label="房间价格" prop="rprice">
          <el-input size="small" v-model="editForm.rprice" auto-complete="off" placeholder="请输入房间价格"></el-input>
        </el-form-item>
          <el-form-item label="空余房间" prop="empty">
          <el-input size="small" v-model="editForm.empty" auto-complete="off" placeholder="请输入空余房间"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click.native="closeDialog">取消</el-button>
        <el-button size="small" type="primary" :loading="loading" class="title" @click.native="submitForm(editForm)">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import {getGoods} from '@/api/Goods'
import Pagination from '@/components/backstage/Pagination'
export default {
  data() {
    return {
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '添加',
      editForm: {
        rid:'',
        hotel_id:'',
        hotelname: '',
        type: '',
        // deptNo: '',
        rprice:1790.74,
        empty:''
      },
      // rules表单验证
      rules: {
        hotelname:[{ required: true, message: '请输入房间号', trigger: 'blur' }],
        type: [
          { required: true, message: '请输入房间类型', trigger: 'blur' }
        ],
        rprice: [{ required: true, message: '请输入价格', trigger: 'blur' }]
      },
      formInline: {        
        type:'',
        hotel_id:''   
      },      
      userparm: [], //搜索权限
      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      },
       paging:{
        page_Num:'',
        page_size:'',
        total:''
      }
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.getdata(this.formInline)
  },
  // 路由钩子函数
  
  // beforeRouteEnter (to, from, next) {
  //   // ... 
  //   console.log('路由离开Goods...');
  //   next()
  // },
  // beforeRouteEnter (to, from, next) {
  //   console.log('路由进入Goods...');
  //   next()
  // },

  /**
   * 里面的方法只有被调用才会执行
   */
  
  methods: {
    // 获取商品列表
    getdata(parameter) {
      this.loading = true     
      // 模拟数据结束
      /***
       * 调用接口，注释上面模拟数据 取消下面注释
       */
     getGoods()
      // deptList(parameter)
        .then(res => {          
           this.loading = false
          // console.log(`df`,res.data);          
          if (res.code==0) {
            this.$message({
              type: 'info',
              message: res.msg
            })
          } else {           
            this.listData = res.data;
            // console.log( this.listData );
            // 分页赋值
              this.paging=res.paging;
              this.pageparm.currentPage = this.paging.page_Num
              this.pageparm.pageSize =  this.paging.page_size
              this.pageparm.total = this.paging.total
                        }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('菜单加载失败，请稍后再试！')
        })
    },
    // 分页插件事件
    callFather(parm) {
       this.$axios.get(`/room/lists?page_num=${parm.currentPage}&page_size=${parm.pageSize}`).then(result=>{
        // console.log(result.data);
        this.loading = false
        this.listData = result.data.data;
        this.pageparm.currentPage = parm.currentPage
        this.pageparm.pageSize = parm.pageSize
        // this.pageparm.total = this.listData.length;
      })
    },
    // 搜索事件
    search() {
      this.$axios.get(`/room/${this.formInline.hotel_id}/${this.formInline.type}`).then(res=>{
        console.log(`搜索`,res.data);
        this.listData  = res.data.data;
        this.pageparm.currentPage = 1
        this.pageparm.pageSize = 10
        this.pageparm.total = 1
      })
    },
    //显示编辑界面
    handleEdit(index, row) {
      this.editFormVisible = true
      if (row != undefined && row != 'undefined') {
        this.title = '修改'
         this.editForm.rid = row.rid
        this.editForm.hotel_id = row.hotel_id
        this.editForm.hotelname = row.hotelname
        this.editForm.type = row.type
        this.editForm.rprice = row.rprice
        this.editForm.empty = row.empty
      } 
    },
    // 编辑、增加页面保存方法
    submitForm(editData) {
      // console.log(`编辑`,editData);
      editData=this.qs.stringify(editData)
      this.$axios.put("/room/edit",editData).then(res => {    
        console.log(res.data.msg);      
        this.editFormVisible = false
        this.loading = false
          if (res.data.code) {
            // console.log(res.data.msg);
            // alert('数据保存成功！')
            this.$message({
            type: 'success',
            message: '数据保存成功！'
            })
            this.getdata(this.formInline)            
           
          } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.editFormVisible = false
              this.loading = false
              this.$message.error('保存失败，请稍后再试！')
            })
    },
  closeDialog() {
      this.editFormVisible = false
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>

 
 